import React, {Component} from 'react';
import {Form, Select, Input, Row, Col, DatePicker, Button, Modal, Table, Collapse, Upload, Icon} from 'antd'
import * as ReactDOM from "react-dom";
import ManagerBody from '../../components/ManagerBody';
import { FetchAPI } from '../../utils/fetch-middleware';
import './style.less';

const Dragger = Upload.Dragger;

@Form.create()
export default class JobAdd extends Component {
    handleClick = (e) => {
        console.log('click ', e);
    }

    // 添加用户信息
    addTcd = (para) => {
        // let sendValue = JSON.parse(JSON.stringify(this.state.validDataSource));
        let sendValue = this.props.form.getFieldsValue();
        debugger;
        console.log(sendValue, 'values');
        FetchAPI('/api/job/add', 'POST', sendValue).then(result => {
            if(result.code === 'ACM0008'){
                Modal.success({
                    title: result.code,
                    content: '添加成功～',
                });
            } else {
                Modal.warning({
                    title: result.code,
                    content: result.message,
                });
            }
        }, err => {
            Modal.error({
                title: 'WRONG',
                content: '系统内部错误，请联系管理员',
            });
        });
    }

    handleOk = (e) => {
        console.log(e);
        this.addTcd();
        this.setState({
            visible: false,
        });
        //重置
        this.props.form.resetFields();

    }

    handleCancel = (e) => {
        console.log(e);
        this.setState({
            visible: false,
        });
    }

    render() {
        const {getFieldDecorator} = this.props.form;
        const props = {
            name: 'file',
            showUploadList: false,
            action: '/upload.do',
        };
        return (
            <Form className="job">
                <Form.Item
                    label="姓名"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 8}}
                >
                    {getFieldDecorator('name', {
                            rules: [{
                                required: true, message: '请输入姓名!',
                            }],
                        }
                    )(
                        <Input style={{width: 250}}/>
                    )}
                </Form.Item>
                <Form.Item
                    label="身份证号"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 8}}
                >
                    {getFieldDecorator('cardId', {
                            rules: [{
                                required: true, message: '请输入身份证号!',
                            }],
                        }
                    )(
                        <Input style={{width: 250}}/>
                    )}
                </Form.Item>
                <Form.Item
                    label="性别"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 8}}
                >
                    {getFieldDecorator('sex', {
                            rules: [{
                                required: true, message: '请选择性别!',
                            }],
                        }
                    )(
                        <Select className="job-sex">
                            <Option value="0">男</Option>
                            <Option value="1">女</Option>
                        </Select>
                    )}
                </Form.Item>
                <Form.Item
                    label="出生日期"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 8}}
                >
                    {getFieldDecorator('birthday', {
                            rules: [{
                                required: true, message: '请选择出生日期!',
                            }],
                        }
                    )(
                        <DatePicker />
                    )}
                </Form.Item>
                <Form.Item
                    label="应聘职位"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 8}}
                >
                    {getFieldDecorator('job', {
                            rules: [{
                                required: true, message: '请输入应聘职位!',
                            }],
                        }
                    )(
                        <Input style={{width: 250}}/>
                    )}
                </Form.Item>
                <Form.Item
                    label="专业"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 8}}
                >
                    {getFieldDecorator('profession', {
                            rules: [{
                                required: true, message: '请输入专业!',
                            }],
                        }
                    )(
                        <Input style={{width: 250}}/>
                    )}
                </Form.Item>
                <Form.Item
                    label="毕业院校"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 8}}
                >
                    {getFieldDecorator('school', {
                            rules: [{
                                required: true, message: '请输入毕业院校!',
                            }],
                        }
                    )(
                        <Input style={{width: 250}}/>
                    )}
                </Form.Item>
                <Form.Item
                    label="最高学历"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 8}}
                >
                    {getFieldDecorator('education', {
                            rules: [{
                                required: true, message: '请输入最高学历!',
                            }],
                        }
                    )(
                        <Input style={{width: 250}}/>
                    )}
                </Form.Item>
                <Form.Item
                    label="手机号"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 8}}
                >
                    {getFieldDecorator('phone', {
                            rules: [{
                                required: true, message: '请输入手机号!',
                            }],
                        }
                    )(
                        <Input style={{width: 250}}/>
                    )}
                </Form.Item>
                <Form.Item
                    label="邮箱"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 8}}
                >
                    {getFieldDecorator('email', {
                            rules: [{
                                required: true, message: '请输入邮箱!',
                            }],
                        }
                    )(
                        <Input style={{width: 250}}/>
                    )}
                </Form.Item>
                <Form.Item
                    label="附件简历"
                    labelCol={{span: 10}}
                    wrapperCol={{span: 8}}
                >
                    {getFieldDecorator('resyme', {
                            rules: [{
                                required: true, message: '请上传附件简历!',
                            }],
                        }
                    )(
                        <Upload {...props}>
                            <Button>
                                <Icon type="upload" /> 上传
                            </Button>
                        </Upload>
                    )}
                </Form.Item>
                <Form.Item style={{textAlign: 'center', marginTop: '30px'}}>
                    <Button onClick={this.handleOk} type="primary" size="large">确认添加</Button>
                </Form.Item>
            </Form>
        );
    }
}
